//
//  ViewController.swift
//  sinaWeiBoAI
//
//  Created by Z.J on 16/3/20.
//  Copyright © 2016年 Z.J. All rights reserved.
//

import UIKit

class ViewController: UITabBarController {

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // 设置tabBar->通过KVC
        let mainTabBar = GMainTabBar()
        setValue(mainTabBar, forKey: "tabBar")
        
        // 设置子控制器
        addChildViewControllers()
       

        
    }
    
    
    // MARK: - 设置子控制器
    
    func addChildViewControllers(){
        // 设置子控制器
        
        // 首页
        let home = GHomeViewController()
        addChildViewController(home, name: "首页", imageName: "tabbar_home")
        // 发现
        let discoverVC = GDiscoverViewController()
        addChildViewController(discoverVC, name: "发现", imageName: "tabbar_discover")
        // 消息
        let message = GMessageViewController()
        addChildViewController(message, name: "消息", imageName: "tabbar_message_center")
        // 个人
        let profile = GProfileViewController()
        addChildViewController(profile, name: "我", imageName: "tabbar_profile")
    }
    
    
    
    func addChildViewController(childController: UIViewController,name:String,imageName:String) {
        
        // 设置item文本
        childController.title = name
//        // 设置点击高亮字体颜色
//        let dict = [NSForegroundColorAttributeName : UIColor.orangeColor()]
//        childController.tabBarItem.setTitleTextAttributes(dict, forState: UIControlState.Selected)
        
        // 设置tabBar的控件颜色
        tabBar.tintColor = UIColor.orangeColor()
        
        // 设置tabbar图片
        childController.tabBarItem.image = UIImage(named: imageName)
        // 拼接高亮图片
//        let hightImage = imageName + "_highlighted"
//
//        // 设置高亮图片.默认情况下选中图片会被渲染成蓝色的.想要使用图片原来的颜色
//        childController.tabBarItem.selectedImage = UIImage(named: hightImage)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        // 创建导航控制器
        let navigation = UINavigationController(rootViewController: childController)
        
        // 添加到tabbar
        addChildViewController(navigation)
    }
}

